package com.wwj.core.wawa.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wwj.core.wawa.entity.Room;
import com.wwj.core.wawa.entity.mapper.RoomMapper;
import com.wwj.core.wawa.service.IRoomService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * Created by Administrator on 2017/11/3.
 */
@Service
public class RoomServiceImpl implements IRoomService {

    @Resource
    private RoomMapper roomMapper;

    @Override
    public Room findById(Integer id) {
        return roomMapper.selectRoomById(id);
    }

    @Override
    public Page<Room> findByPage(int offset, int limit) {
        PageHelper.offsetPage(offset, limit);
        return (Page<Room>)roomMapper.selectRooms();
    }

    @Override
    public Page<Room> findByPage(Map<String, Object> params,int offset, int limit) {
        PageHelper.offsetPage(offset, limit);
        return (Page<Room>)roomMapper.findByPage(params);
    }

    @Override
    public void modifyPlayerNumber(Integer roomId, int increment) {
        roomMapper.updateRoomPlayerNumber(roomId, increment);
    }

    @Override
    public int createRoom(Room room) throws Exception {
        roomMapper.insertRoom(room);
        return 1;
    }

    @Override
    public void updateRoom(Room room) {
        roomMapper.updateRoom(room);
    }

    @Override
    public int findByWaWaTypeId(Integer id) {
        return roomMapper.findByWaWaTypeId(id);
    }


}
